<template>
  <view class="life-service-container">
    <!-- 顶部横幅 - 纯色背景替代图片 -->
    <view class="banner">
      <view class="banner-content">
        <text class="banner-title">充电周边生活服务</text>
        <text class="banner-subtitle">便捷生活 一站搞定</text>
      </view>
    </view>
    
    <!-- 服务分类 -->
    <view class="service-category">
      <view class="category-title">
        <text class="title-text">便捷服务</text>
        <text class="subtitle">充电周边 一站搞定</text>
      </view>
      
      <view class="category-grid">
        <view class="category-item" v-for="(item, index) in categories" :key="index" @click="onCategoryClick(item)">
          <view class="category-icon" :style="{backgroundColor: getColor(index)}">
            <text class="icon-text">{{item.icon}}</text>
          </view>
          <text class="category-name">{{item.name}}</text>
        </view>
      </view>
    </view>
    
    <!-- 附近商家 -->
    <view class="nearby-shops">
      <view class="section-header">
        <text class="section-title">附近商家</text>
        <text class="section-more">查看更多 ></text>
      </view>
      
      <view class="shop-list">
        <view class="shop-card" v-for="(shop, index) in shops" :key="index">
          <view class="shop-image" :style="{backgroundColor: getShopColor(index)}"></view>
          <view class="shop-info">
            <text class="shop-name">{{shop.name}}</text>
            <text class="shop-distance">{{shop.distance}}km | {{shop.category}}</text>
            <view class="shop-tags">
              <text class="tag" v-for="(tag, i) in shop.tags" :key="i">{{tag}}</text>
            </view>
          </view>
        </view>
      </view>
    </view>
    
    <!-- 充电优惠 -->
    <view class="discount-section">
      <view class="section-header">
        <text class="section-title">充电优惠</text>
      </view>
      
      <view class="discount-cards">
        <view class="discount-card">
          <view class="discount-image" style="background-color: #ffeb3b;"></view>
          <view class="discount-info">
            <text class="discount-title">充电满50减5元</text>
            <text class="discount-time">有效期至2023-12-31</text>
          </view>
        </view>
        
        <view class="discount-card">
          <view class="discount-image" style="background-color: #4caf50;"></view>
          <view class="discount-info">
            <text class="discount-title">新用户首充立减10元</text>
            <text class="discount-time">有效期至2023-12-31</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      categories: [
        { name: '餐饮美食', icon: '🍔' },
        { name: '便利店', icon: '🏪' },
        { name: '卫生间', icon: '🚻' },
        { name: '停车场', icon: '🅿️' },
        { name: '休息区', icon: '🛋️' },
        { name: '洗车服务', icon: '🚗' }
      ],
      shops: [
        {
          name: '星巴克咖啡',
          distance: 0.5,
          category: '咖啡厅',
          tags: ['充电优惠', 'WIFI']
        },
        {
          name: '7-11便利店',
          distance: 0.3,
          category: '便利店',
          tags: ['24小时', '充电宝']
        },
        {
          name: '肯德基',
          distance: 0.8,
          category: '快餐',
          tags: ['充电优惠', '卫生间']
        }
      ]
    }
  },
  methods: {
    onCategoryClick(item) {
      uni.showToast({
        title: `点击了${item.name}`,
        icon: 'none'
      })
    },
    getColor(index) {
      const colors = ['#ffeb3b', '#4caf50', '#2196f3', '#ff9800', '#9c27b0', '#f44336'];
      return colors[index % colors.length];
    },
    getShopColor(index) {
      const colors = ['#e3f2fd', '#e8f5e9', '#fff3e0'];
      return colors[index % colors.length];
    }
  }
}
</script>

<style>
.life-service-container {
  padding-bottom: 40rpx;
  background-color: #f5f5f5;
}

/* 横幅样式 - 纯色背景 */
.banner {
  width: 100%;
  height: 300rpx;
  background: linear-gradient(135deg, #2196F3, #00BCD4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-direction: column;
}
.banner-content {
  text-align: center;
}
.banner-title {
  font-size: 40rpx;
  font-weight: bold;
  display: block;
  margin-bottom: 10rpx;
}
.banner-subtitle {
  font-size: 28rpx;
  opacity: 0.9;
}

/* 服务分类 */
.service-category {
  background-color: #fff;
  margin: 20rpx;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}
.category-title {
  margin-bottom: 30rpx;
}
.title-text {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  margin-right: 20rpx;
}
.subtitle {
  font-size: 26rpx;
  color: #999;
}
.category-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.category-item {
  width: 30%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30rpx;
}
.category-icon {
  width: 100rpx;
  height: 100rpx;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15rpx;
}
.icon-text {
  font-size: 50rpx;
}
.category-name {
  font-size: 26rpx;
  color: #666;
  text-align: center;
}

/* 附近商家 */
.nearby-shops {
  background-color: #fff;
  margin: 20rpx;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
}
.section-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}
.section-more {
  font-size: 26rpx;
  color: #999;
}
.shop-list {
  display: flex;
  flex-direction: column;
}
.shop-card {
  display: flex;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #eee;
}
.shop-image {
  width: 160rpx;
  height: 160rpx;
  border-radius: 8rpx;
  margin-right: 20rpx;
}
.shop-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.shop-name {
  font-size: 30rpx;
  color: #333;
  font-weight: bold;
}
.shop-distance {
  font-size: 26rpx;
  color: #999;
}
.shop-tags {
  display: flex;
  flex-wrap: wrap;
}
.tag {
  font-size: 22rpx;
  color: #07c160;
  background-color: #e8f8f0;
  padding: 4rpx 12rpx;
  border-radius: 20rpx;
  margin-right: 10rpx;
  margin-top: 10rpx;
}

/* 充电优惠 */
.discount-section {
  background-color: #fff;
  margin: 20rpx;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}
.discount-cards {
  display: flex;
  flex-direction: column;
}
.discount-card {
  display: flex;
  margin-bottom: 20rpx;
  background-color: #f9f9f9;
  border-radius: 12rpx;
  overflow: hidden;
  height: 140rpx;
}
.discount-image {
  width: 200rpx;
  height: 100%;
}
.discount-info {
  flex: 1;
  padding: 20rpx;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.discount-title {
  font-size: 28rpx;
  color: #333;
  font-weight: bold;
}
.discount-time {
  font-size: 24rpx;
  color: #999;
}
</style>